<!DOCTYPE html>
<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <script type="text/javascript" src="./promise.js"></script>
</head>
<body style="height: 2000px;">
    <script>
        // function debounce(callback, n) {
        //     let Timer;
        //     return () => {
        //         console.log(Timer)
        //         if (Timer) {
        //             clearTimeout(Timer)
        //         }
        //         Timer = setTimeout(callback, n)
        //     }
        // }
        function throttle(callback, n) {
            let Timer ;
            return () => {
                console.log(Timer)
                if (Timer) {
                    return;
                }
                Timer = setTimeout(() => {
                    callback();
                    Timer = null;
                }, n)
            }
        }
        var throttle1 = function(func, delay){
            var prev = Date.now();
            return function(){
                var context = this;
                var args = arguments;
                var now = Date.now();
                if(now-prev>=delay){
                    func.apply(context,args);
                    prev = Date.now();
                }
            }
        }
        // throttle1(()=>{console.log("执行中！！！")}, 1000)
        window.addEventListener('scroll', throttle1(()=>{console.log("执行中！！！")}, 5000));

        // var add = function(x){
           
        //     var sum = 1;
        //     var tmp = function(x){
               
        //         sum = sum + x;
        //     return tmp;
        //     }
        //     tmp.toString = function(){
        //         console.log(1);
        //         return sum;
        //     }
        //     return tmp;
        // }
        // add(1)(2)(3)
    </script>
</body>
</html>